package com.guojian.common.proxy;

import java.security.Provider.Service;
import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

import org.omg.IOP.ServiceContextListHolder;

/**
 * 
 * 抽象工厂模式
 * @author GuoJian
 *
 */
public abstract class ProxyFactory {

	public <T> T createProxy(T target) {
		return createProxyInstance(target);
	}

	protected abstract <T> T createProxyInstance(T target);

	/*@SuppressWarnings("unchecked")
	private  static <T> T createProxyInstance(T target, InvocationHandler handler) {
		Object object = Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), handler);
		System.out.println(object);
		return (T) object;
	}*/

	public static void main(String[] args) {
		//Pbean a = new Pbean();
		//IPbean pbean = ProxyFactory.createProxy(a, new MapperInvocationHandler(a));
		//System.out.println(pbean.say(""));

		Pbean a = new Pbean();

		Pbean aproxy = cn.hutool.aop.proxy.ProxyFactory.createProxy(a, new PbeanAspect());

		System.out.println(aproxy);

		ServiceLoader<cn.hutool.aop.proxy.ProxyFactory> aaa = ServiceLoader.load(cn.hutool.aop.proxy.ProxyFactory.class);

		Iterator<cn.hutool.aop.proxy.ProxyFactory> iterator = aaa.iterator();

		while (iterator.hasNext()) {

		}

	}

}
